package com.hytc.mymall.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.view.animation.Interpolator;
import android.widget.Scroller;

import java.lang.reflect.Field;

/**
 * Created by Administrator on 2016/12/2.
 */

public class ViewPagerScroller extends Scroller
{
    private int mScrollDuration;

    public ViewPagerScroller(final Context context) {
        super(context);
        this.mScrollDuration = 2000;
    }

    public ViewPagerScroller(final Context context, final Interpolator interpolator) {
        super(context, interpolator);
        this.mScrollDuration = 2000;
    }

    public ViewPagerScroller(final Context context, final Interpolator interpolator, final boolean b) {
        super(context, interpolator, b);
        this.mScrollDuration = 2000;
    }

    public void initViewPagerScroll(final ViewPager viewPager) {
        try {
            final Field declaredField = ViewPager.class.getDeclaredField("mScroller");
            declaredField.setAccessible(true);
            declaredField.set(viewPager, this);
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void setScrollDuration(final int mScrollDuration) {
        this.mScrollDuration = mScrollDuration;
    }

    public void startScroll(final int n, final int n2, final int n3, final int n4) {
        super.startScroll(n, n2, n3, n4, this.mScrollDuration);
    }

    public void startScroll(final int n, final int n2, final int n3, final int n4, final int n5) {
        super.startScroll(n, n2, n3, n4, this.mScrollDuration);
    }
}
